home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / performDiskCache.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  11.3 KB  |  375 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //
  18. //  Alias|Wavefront Script File
  19. //  MODIFY THIS AT YOUR OWN RISK
  20. //
  21. //  Creation Date:  10 Oct 2000
  22. //
  23. //  Description:
  24. //        This script provides an option box dialog for the diskCache command.
  25. //
  26. //    Input Arguments:
  27. //        boolean isCreationMode    true - we are in creation mode
  28. //                                false - we are in deletion mode
  29. //        boolean showOptionBox    true - show the option box dialog
  30. //                                false - just execute the command
  31. //
  32. global proc disableDiskCacheAttrs(string $parent) {
  33.     setParent $parent;
  34.     string $showStartEnd = `radioButtonGrp -query -sl createDiskCacheTimeRange3`;
  35.  
  36.     if( $showStartEnd ) {
  37.         floatFieldGrp -e -enable true createDiskCacheStartEndTime;
  38.     } else {
  39.         floatFieldGrp -e -enable false createDiskCacheStartEndTime;
  40.     }
  41. }
  42.  
  43. proc setOptionVars(int $forceFactorySettings)
  44. {
  45.     if( $forceFactorySettings || !`optionVar -exists createDiskCacheTimeRange`)
  46.         optionVar -intValue createDiskCacheTimeRange 2;
  47.  
  48.     if( $forceFactorySettings || !`optionVar -exists createDiskCacheStartTime`)
  49.         optionVar -floatValue createDiskCacheStartTime 1;
  50.  
  51.     if( $forceFactorySettings || !`optionVar -exists createDiskCacheEndTime`)
  52.         optionVar -floatValue createDiskCacheEndTime 10;
  53.  
  54.     if( $forceFactorySettings || !`optionVar -exists createDiskCacheSampling`) 
  55.         optionVar -intValue createDiskCacheSampling 1;
  56.  
  57.     if( $forceFactorySettings || !`optionVar -exists createDiskCacheSamplingRate`)
  58.         optionVar -intValue createDiskCacheSamplingRate 1;
  59. }
  60.  
  61. global proc createDiskCacheSetup (string $parent, int $forceFactorySettings)
  62. {
  63.     setOptionVars($forceFactorySettings);
  64.     setParent $parent;
  65.  
  66.     eval( "radioButtonGrp -e -sl 1 createDiskCacheTimeRange" + 
  67.           `optionVar -query createDiskCacheTimeRange` );
  68.  
  69.     floatFieldGrp -e 
  70.         -v1 `optionVar -query createDiskCacheStartTime` 
  71.         -v2 `optionVar -query createDiskCacheEndTime` 
  72.         createDiskCacheStartEndTime;
  73.  
  74.     radioButtonGrp -e 
  75.         -sl `optionVar -query createDiskCacheSampling` 
  76.         createDiskCacheSampling;
  77.  
  78.     intSliderGrp -e 
  79.         -v `optionVar -query createDiskCacheSamplingRate`
  80.         createDiskCacheSamplingRate;
  81.  
  82.     disableDiskCacheAttrs $parent;
  83. }
  84.  
  85. global proc createDiskCacheCallback(string $parent)
  86. {
  87.     int $timeMode = 1;
  88.  
  89.     if( `radioButtonGrp -q -sl createDiskCacheTimeRange1` ) {
  90.         $timeMode = 1;
  91.     }
  92.     else if( `radioButtonGrp -q -sl createDiskCacheTimeRange2` ) {
  93.         $timeMode = 2;
  94.     }
  95.     else if( `radioButtonGrp -q -sl createDiskCacheTimeRange3` ) {
  96.         $timeMode = 3;
  97.     }
  98.  
  99.     optionVar -iv createDiskCacheTimeRange $timeMode;
  100.     optionVar -fv createDiskCacheStartTime 
  101.         `floatFieldGrp -q -v1 createDiskCacheStartEndTime`;
  102.     optionVar -fv createDiskCacheEndTime
  103.         `floatFieldGrp -q -v2 createDiskCacheStartEndTime`;
  104.  
  105.     optionVar -iv createDiskCacheSampling 
  106.         `radioButtonGrp -query -sl createDiskCacheSampling`;
  107.  
  108.     optionVar -iv createDiskCacheSamplingRate
  109.         `intSliderGrp -q -v createDiskCacheSamplingRate`;
  110. }
  111.  
  112. global proc createDiskCachemcjCallback(string $parent)
  113. {
  114.     createDiskCacheCallback $parent;
  115.     performDiskCache true false mcj;
  116. }
  117.  
  118. proc creationOptionBox(string $cacheType)
  119. {
  120.     // Name of the command for this option box 
  121.     //
  122.     string $commandName = "createDiskCache";
  123.  
  124.     // Build the option box "methods"
  125.     //
  126.     string $callback = ($commandName + $cacheType + "Callback ");
  127.     string $setup = ($commandName + "Setup");
  128.     
  129.     //  STEP 1:  Get the option box.
  130.     //  ============================
  131.     //
  132.     //  The value returned is the name of the layout to be used as
  133.     //  the parent for the option box UI.
  134.     //
  135.     string $layout = getOptionBox();
  136.     setParent $layout;
  137.  
  138.     //  STEP 2:  Pass the command name to the option box.
  139.     //  =================================================
  140.     //
  141.     //  Any default option box behaviour based on the command name is set
  142.     //  up with this call.  For example, updating the 'Help' menu item with
  143.     //  the name of the command.
  144.     //
  145.     setOptionBoxCommandName($commandName);
  146.  
  147.     //  STEP 3:  Activate the default UI template.
  148.     //  ==========================================
  149.     //
  150.     //  Activate the default UI template so that the layout of this
  151.     //  option box is consistent with the layout of the rest of the
  152.     //  application.
  153.     //
  154.     setUITemplate -pushTemplate DefaultTemplate;
  155.  
  156.     //  STEP 4: Create option box contents.
  157.     //  ===================================
  158.     //
  159.     //  This, of course, will vary from option box to option box.
  160.            
  161.     //  Turn on the wait cursor.
  162.     //
  163.     waitCursor -state 1;
  164.  
  165.     tabLayout -scr true -tv false;
  166.  
  167.     string $parent = `columnLayout -adjustableColumn 1`;
  168.  
  169.     //    Create the widgets for this option box
  170.     //
  171.     radioButtonGrp 
  172.         -label "Cache Time Range" -nrb 1
  173.         -l1 "Render Globals"
  174.         -cc ( "disableDiskCacheAttrs " + $parent )
  175.         createDiskCacheTimeRange1;
  176.  
  177.     radioButtonGrp 
  178.         -label "" -nrb 1
  179.         -scl createDiskCacheTimeRange1
  180.         -cc ( "disableDiskCacheAttrs " + $parent )
  181.         -l1 "Time Slider"
  182.         createDiskCacheTimeRange2;
  183.  
  184.     radioButtonGrp 
  185.         -label "" -nrb 1
  186.         -scl createDiskCacheTimeRange1
  187.         -l1 "Start/End"
  188.         -cc ( "disableDiskCacheAttrs " + $parent )
  189.         createDiskCacheTimeRange3;
  190.     
  191.     floatFieldGrp -label "Start/End" -nf 2 
  192.         createDiskCacheStartEndTime;
  193.     
  194.     separator -h 5 -style "none";
  195.     
  196.     radioButtonGrp -nrb 2 -l "Sampling" -l1 "Over" -l2 "Under" 
  197.         createDiskCacheSampling;
  198.  
  199.     intSliderGrp -l "Rate" -min 1 -max 5 -fmn 1 -fmx 100 -value 1
  200.         createDiskCacheSamplingRate;
  201.  
  202.     //    Turn off the wait cursor.
  203.     //
  204.     waitCursor -state 0;
  205.     
  206.     //    Step 5: Deactivate the default UI template.
  207.     //  ===========================================
  208.     //
  209.     setUITemplate -popTemplate;
  210.  
  211.     //    Step 6: Customize the buttons.  
  212.     //    ==============================
  213.     //
  214.     //    Provide more descriptive labels for the buttons.  This is not 
  215.     //    necessary, but in some cases, for example, a button labelled 
  216.     //    'Create' may be more meaningful to the user than one labelled
  217.     //    'Apply'.
  218.     //
  219.     //  Disable those buttons that are not applicable to the option box.
  220.     //
  221.     //    Attach actions to those buttons that are applicable to the option
  222.     //    box.  Note that the 'Close' button has a default action attached 
  223.     //    to it that will hide the window.  If a a custom action is
  224.     //    attached to the 'Close' button then be sure to call the 'hide the
  225.     //    option box' procedure within the custom action so that the option
  226.     //    box is hidden properly.
  227.  
  228.     //    'Apply' button.
  229.     //
  230.     string $applyBtn = getOptionBoxApplyBtn();
  231.     button -edit -label "Create"
  232.         -command ($callback + " " + $parent)
  233.         $applyBtn;
  234.  
  235.     //  'Save' button.
  236.     //
  237.     string $saveBtn = getOptionBoxSaveBtn();
  238.     button -edit 
  239.         // Don't use $callback since that has cacheType specific
  240.         // stuff in it and will cause the "save" button to execute
  241.         // the createDiskCache proc for that cacheType!
  242.         //
  243.         -command ($commandName+"Callback" + " " + $parent + "; hideOptionBox")
  244.         $saveBtn;
  245.  
  246.     // 'Reset' button
  247.     string $resetBtn = getOptionBoxResetBtn();
  248.     int $resetToDefaults = 1;
  249.     button -edit 
  250.         -command ($setup + " " + $parent + " " + $resetToDefaults)
  251.         $resetBtn;
  252.  
  253.     //    Step 7: Set the option box title.
  254.     //    =================================
  255.     //
  256.     setOptionBoxTitle("Create Disk Cache Options");
  257.  
  258.     //    Step 8: Customize the 'Help' menu item text.
  259.     //    ============================================
  260.     //
  261.     setOptionBoxHelpTag( "CreateJiggleDiskCache" );
  262.  
  263.     //    Step 9: Set the current values of the option box.
  264.     //    =================================================
  265.     //
  266.     eval ($setup + " " + $parent + " " + 0);
  267.     
  268.     //    Step 10: Show the option box.
  269.     //    =============================
  270.     //
  271.     showOptionBox();
  272. }
  273.  
  274. proc string creation(string $cacheType)
  275. {
  276.     string $cmd;
  277.  
  278.     // do nothing if therre is no diskCache
  279.     string $allDiskCaches[] = `ls -type "diskCache"`;
  280.     if( size($allDiskCaches) < 1 ) {
  281.         string $msg = "No diskCache nodes found.  No caches to create.";
  282.         warning $msg;
  283.         return $cmd;
  284.     }
  285.  
  286.     // Verify all diskCache files have unique names
  287.     int $n, $m;
  288.     for($n = 1; $n < size($allDiskCaches); $n++) {
  289.         string $cacheName = `getAttr ($allDiskCaches[$n] + ".cacheName")`;
  290.         if( size($cacheName) == 0 )
  291.             $cacheName = `getAttr ($allDiskCaches[$n] + ".hiddenCacheName")`;
  292.         for( $m = 0; $m < $n; $m++) {
  293.             string $preCacheName = `getAttr ($allDiskCaches[$m] + ".cacheName")`;
  294.             if( size($preCacheName) == 0 )
  295.                 $prevCacheName = `getAttr ($allDiskCaches[$m] + ".hiddenCacheName")`;
  296.             if( $cacheName == $preCacheName ) {
  297.                 string $msg = ( "Disk cache is not created because " + 
  298.                                 $allDiskCaches[$m] + 
  299.                                 " and " + 
  300.                                 $allDiskCaches[$n] + 
  301.                                 " have disk cache name conflict, and one of them has to be renamed." );
  302.                 error $msg;
  303.                 return $cmd;
  304.             }
  305.         }
  306.     }
  307.  
  308.     verifyWorkspaceFileRule( "diskCache", "data" );
  309.  
  310.     string $frameRangeOption = "Time Slider";
  311.     int $rangeMode = `optionVar -query createDiskCacheTimeRange`;
  312.     if( $rangeMode == 1 ) {
  313.         $frameRangeOption = "Render Globals";
  314.     } else if( $rangeMode == 2 ) {
  315.         $frameRangeOption = "Time Slider";
  316.     } else if( $rangeMode == 3 ) {
  317.         $frameRangeOption = "Start/End";
  318.     }                               
  319.  
  320.     string $samplingType   = "";
  321.     if( `optionVar -query createDiskCacheSampling` == 1 ) {
  322.         $samplingType = "-os";
  323.     }
  324.  
  325.     float  $diskCacheStartTime =`optionVar -query createDiskCacheStartTime`;
  326.     float  $diskCacheEndTime   =`optionVar -query createDiskCacheEndTime`;
  327.     int    $samplingRate       =`optionVar -query createDiskCacheSamplingRate`;
  328.  
  329.     if( $frameRangeOption == "Start/End" ) {
  330.         $cmd =  "diskCache" + " -frt \"" + $frameRangeOption + "\"" +
  331.                               " -st " + $diskCacheStartTime +
  332.                               " -et " + $diskCacheEndTime +
  333.                               " "     + $samplingType + 
  334.                               " -ct " + $cacheType + 
  335.                               " -sr  " + $samplingRate;
  336.     } else {
  337.         // $frameRangeOption == "Time Slider" or "Render Globals"
  338.         $cmd =  "diskCache" + " -frt \"" + $frameRangeOption + "\"" +
  339.                               " "     + $samplingType + 
  340.                               " -ct " + $cacheType + 
  341.                               " -sr " + $samplingRate;
  342.     }
  343.  
  344.     // Only affect enabled cache nodes.
  345.     //
  346.     $cmd = $cmd + " -enabledCachesOnly ";
  347.  
  348.     return $cmd;
  349. }
  350.  
  351. global proc string performDiskCache( int $isCreation, int $showOptionBox, string $cacheType )
  352. {
  353.     if( $cacheType != "mcj" ) {
  354.         error( "Use performFluidsDiskCache for mcfi and mcfp cache types." );
  355.         return "";
  356.     }
  357.  
  358.     string $cmd = "";
  359.     if( $isCreation ) {
  360.         if( $showOptionBox ) 
  361.             creationOptionBox $cacheType;
  362.         else {
  363.             setOptionVars(false);
  364.             $cmd = creation($cacheType);
  365.             evalEcho($cmd);
  366.         }
  367.     } else { // is deletion 
  368.         // delete all disk cache files
  369.         $cmd = "diskCache -d";
  370.         evalEcho($cmd);
  371.     }
  372.     return $cmd;
  373. }
  374.  
  375.